/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cdp;

import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author Rodrigo
 */
@MappedSuperclass
public class ObjetoPersistente implements Serializable{
    
    private long id;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    public long getId() {
        return id;
    }
    
    /**
     * Construtor.
     */
    public ObjetoPersistente(){
        
    }
    
    /**
     * Construtor que recebe como parametro:
     * @param id do objeto a ser instanciado.
     */
    public ObjetoPersistente(long id){
        this.id = id;
    }
    
    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 97 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }
    
    @Override
    public boolean equals(Object object){
        if(object.getClass()==this.getClass()){
            ObjetoPersistente aux = (ObjetoPersistente) object;
            if(this.getId()==aux.getId()){
                return true;
            }
        }
        return false;
    }
    
    public boolean ehValido(){
        return true;
    }
}
